package com.example.lawyer.databind.assembly;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.lawyer.R;

public class UserInfoCoverData {


    //头像
    public ObservableField<String> image = new ObservableField<>();
    //昵称
    public ObservableField<String> nickn = new ObservableField<>();
    //称号
    public ObservableField<String> title = new ObservableField<>();
    //状态
    public ObservableField<Boolean> islogin = new ObservableField<>();
    //个人简介
    public ObservableField<String> introduce = new ObservableField<>();
    //渲染头像
    @BindingAdapter("imgurl")
    public static void imgurl(View view,String url)
    {

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.default_userimg)
                .error(R.mipmap.default_userimg)
                .override(100, 100)
                .fitCenter()
                .circleCrop()
                .skipMemoryCache(false)
                .diskCacheStrategy(DiskCacheStrategy.ALL);


        if(url!=null)
        {

            Glide.with(view).load(url).apply(requestOptions).into((ImageView) view);

        }else {
            Drawable drawable = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                drawable = view.getContext().getDrawable(R.mipmap.default_userimg);
                Glide.with(view).load(drawable).apply(requestOptions).into((ImageView) view);
            }

        }
    }
    //处昵称
    @BindingAdapter("setnick")
    public static void nicks(View view,String nick)
    {
        TextView textView = (TextView) view;
        if(nick==null)
        {
            textView.setText("请登录");
        }else {
            textView.setText(nick);
        }
    }


    //登录点击
    public void loginclick(View view)
    {
        Intent intent = new Intent();
        intent.setAction("AccountLogin");
        view.getContext().startActivity(intent);

    }

}
